var belongType = T.p("belongType");
var belongId = T.p("belongId");
if(!belongType){
    belongType =  1;
}

$(function () {
    $("#jqGrid").jqGrid({
        url: '../workParams/list',
        datatype: "json",
        postData:{belongId:belongId,belongType:belongType},
        colModel: [
			{ label: 'id', name: 'id', width: 50, key: true },
			{ label: '参数名称', name: 'paramKey',index:'param_key', width: 80 },
			{ label: '类型', name: 'type',index:'type', width: 80 , formatter: function (value, options, row) {
                    return T.showDictItemName("param_type",value);
			}},
			{ label: '数据库', name: 'dbKey',index:'db_key', width: 80 , formatter: function (value, options, row) {
                    return T.showDictDynaName("db_key",value);
                }
            },
			{ label: '更新时间', name: 'updateTime',index:'update_time', width: 80 }
        ],
		viewrecords: true,
        height: 800,
        rowNum: 20,
		rowList : [20,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
			root: "page.data",
			page: "page.pageNo",
			total: "page.pageCount",
			records: "page.count"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		isShowCond:true,
        btnText:'隐藏',
        qryForm:{
            paramKey:''
        },
		isShowback:belongType==1?false:true
	},
	methods: {
		reset: function(){
			this.qryForm.paramKey = '';
        },
        query: function () {
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{paramKeyLike:'%'+vm.qryForm.paramKey+'%'
                },
                page:1
            }).trigger("reloadGrid");
        },
        toggle:function(){
            this.isShowCond = !this.isShowCond;

            if(this.isShowCond==true){
                this.btnText = "隐藏"
            }else if(this.isShowCond==false){
                this.btnText = "查询"
            }

        },
        create:function (event) {
            location.href = "workParams_add.html?belongType="+belongType+"&belongId="+belongId;
        },
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			
			location.href = "workParams_add.html?id="+id+"&belongType="+belongType+"&belongId="+belongId;
		},
		back:function (event) {
			history.go(-1);
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../workParams/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
        execReferWork:function () {
			if(belongType == '2'&&belongId!=null){
                var paramsId = getSelectedRow();
                if(paramsId == null){
                    return ;
                }

                confirm('确定要排队执行此任务？', function(){
                    $.ajax({
                        type: "POST",
                        url: "../workParams/execReferWork",
                        data: {paramsId:paramsId,workId:belongId},
                        contentType:'application/x-www-form-urlencoded; charset=UTF-8',
                        dataType: "json",
                        success: function(r){
                            if(r.code === 0){
                                alert('操作成功', function(index){
                                    vm.back();
                                });
                            }else{
                                alert(r.msg);
                            }
                        }
                    });

                });
			}
        }
	}
});
